<?php
if (!defined('ipos')) die("Please contact Y!m: ichphien_pro or Email: ichphien_pro@yahoo.com.");
// ket noi database
$link_music 	= 	mysql_connect(SERVER_HOST,DATABASE_USER,DATABASE_PASS, true);
$dataconnect	=	mysql_select_db(DATABASE_NAME, $link_music);
if(!$dataconnect)	die("Error: ".mysql_error());	

// class mysql database 
class	iposmysql {
	
	/**
	 * @copyright 2014 GES Inc,
	 * @author GES.HoangPV
	 * @param string $item
	 * @param string $table
	 * @param string $con
	 */
	public function database($item,$table,$con){
		global $link_music;
		$table	=	trim($table);
		$arr=null;
		$i=(float) 0;
		$sql="SELECT $item FROM ".DATABASE_NAME.'.'.DATABASE_FX.$table;
		if($con!="")
			$sql.=" WHERE $con";
		$result= mysql_query($sql,$link_music);
		if ($result){
			while($myrow = mysql_fetch_row($result)){
				$count = mysql_num_fields($result);
				for($j=(float)0;$j<$count;$j++)
					$arr[$i][$j]=$myrow[$j];
				$i++;
			}
			mysql_free_result($result);
			return $arr;
	   }
	   else
		return false;
	}
	public function dbdelete($table,$item) {
		@mysql_query("DELETE FROM ".DATABASE_FX.$table." WHERE $item");
	}
	
	public function dbupdate($table,$name,$item) {
		@mysql_query("UPDATE ".DATABASE_FX.$table." SET $name WHERE $item");
	}
	
	public function dbinstall($table,$name,$item) {
		@mysql_query("INSERT INTO ".DATABASE_FX.$table." ($name) VALUES ($item)");
	}
}
// bbcode
class iposbbcode{
    public function gethtml($str){
      $bb[] = "#\[b\](.*?)\[/b\]#si";
      $html[] = "<b>\\1</b>";
      $bb[] = "#\[i\](.*?)\[/i\]#si";
      $html[] = "<i>\\1</i>";
      $bb[] = "#\[u\](.*?)\[/u\]#si";
      $html[] = "<u>\\1</u>";
      $bb[] = "#\[hr\]#si";
      $html[] = "<hr>";
      $str 		= 	preg_replace ($bb, $html, $str);
      $patern	=	"#\[url href=([^\]]*)\]([^\[]*)\[/url\]#i";
      $replace	=	'<a href="\\1" target="_blank" rel="nofollow">\\2</a>';
	  $str		=	preg_replace($patern, $replace, $str); 
      $patern	=	"#\[color=([^\]]*)\]([^\[]*)\[/color\]#i";
      $replace	=	'<span style="color:\\1;">\\2</span>';
	  $str		=	preg_replace($patern, $replace, $str); 
      $patern	=	"#\[img\]([^\[]*)\[/img\]#i";
      $replace	=	'<img src="\\1" alt=""/>';
      $str=preg_replace($patern, $replace, $str);  
	  $str=nl2br($str);
      return $str;
    }
}

function get_data($table, $field, $con){
	global $db;
	$arr = $db->database($field , $table , $con);
	if(count($arr) > 0)
		return $arr[0][0];
	else
		return false;
}

function GetTIMEDATE($date) {
	$date = date("g:i A d/m/Y",$date);
	return $date;
}

function getConfig($key){
	global $db;
	$arr = $db->database("cf_value","config","cf_id ='".$key."'");
	if(count($arr) > 0)
		return $arr[0][0];
	else
		return false;
}

function m_get_config($key){
	global $db;
	$arr = $db->database("cf_value","config","cf_name ='".$key."'");
	if(count($arr) > 0)
		return $arr[0][0];
	else
		return false;
}

function DeleteCache($dir,$rf = "") {
	echo 'Ä�ang cáº­p nháº­t dá»¯ liá»‡u.';
    $mydir = opendir($dir);
          while(false !== ($file = readdir($mydir))) {
              if($file != "." && $file != "..") {
                  if(!is_dir($dir.$file)) {
                          unlink($dir.$file) or DIE("KhÃ´ng thá»ƒ xÃ³a $dir$file<br />");
                  }

              }
          }
	closedir($mydir);
	if($rf != "") {
		header ("Location: ../index.php");
	}
	exit();
}
function delFile($path){
	$path	=	$_SERVER["DOCUMENT_ROOT"].$path;
	if(file_exists($path)){
		@unlink($path);
		return true;
	}else
		return false;
}

// set cookie
function _SETCOOKIE($name, $value = "",$time = 2592000){ 
	$expires = time() + $time; 
	setcookie($name, $value, $expires, "/");
} 
// lay cookie
function _GETCOOKIE($name){ 
	if (isset($_COOKIE[$name])) return urldecode($_COOKIE[$name]); 
	else return FALSE; 
}
?>